﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace TrinityAPI.Base.Models
{
    public class APIContext
    {
        [ThreadStatic]
        public static bool LogRequest;

        [ThreadStatic]
        public static bool LogResponse;

        [ThreadStatic]
        public static string LogRepositoryName;

        [ThreadStatic]
        public static string LogConfigFile;

        [ThreadStatic]
        public static string ResponseContentType;

        [ThreadStatic]
        public static JObject ResponseHeaders;

        [ThreadStatic]
        public static string Service;

        [ThreadStatic]
        public static string Version;

        [ThreadStatic]
        public static string ApiName;

        [ThreadStatic]
        public static string Language;

        [ThreadStatic]
        public static DateTime ConfigLastModTime;

        [ThreadStatic]
        public static JObject ErrorMessages;

        [ThreadStatic]
        public static JObject DefaultErrorMessages;

        [ThreadStatic]
        public static ScriptEngine ScriptEngine;

        [ThreadStatic]
        public static Dictionary<string, int> ExecuteChain;

        public static string ApiFullName
        {
            get { return string.Format("{0}_{1}_{2}", Service, Version, ApiName); }
        }

        public static void Init()
        {
            LogRequest = true;
            LogResponse = false;
            LogRepositoryName = null;
            LogConfigFile = null;
            ResponseContentType = null;
            ResponseHeaders = null;
            Service = null;
            Version = null;
            ApiName = null;
            Language = "en";
            ConfigLastModTime = DateTime.MinValue;
            ErrorMessages = null;
            DefaultErrorMessages = null;
            ScriptEngine = null;
            ExecuteChain = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
        }
    }
}
